/**	\author    coidgen 0.9.2
	\version    (27.0 build 81)
	\date      
	\brief     
*/



#include "example_client.h"
#include "coid/comm/binstream/container_linear.h"




namespace coid {

struct COID_TABLE_TestClass_27_0  {
	opcd (COID_TABLE_TestClass_27_0::*disconnect)();
	opcd (COID_TABLE_TestClass_27_0::*get_length__0)( int & length, const std::string & str );
	opcd (COID_TABLE_TestClass_27_0::*get_vect_length__1)( int & length, const std::vector<trivTypes> & vec );
	opcd (COID_TABLE_TestClass_27_0::*multiply__2)( double a, double b, double & result );
	opcd (COID_TABLE_TestClass_27_0::*add_one__3)( int & number );
	opcd (COID_TABLE_TestClass_27_0::*set_status__4)( int & old_status, int new_status );
	opcd (COID_TABLE_TestClass_27_0::*set_birth_date__5)(std::vector< birth_date > & birt_d);
	opcd (COID_TABLE_TestClass_27_0::*cmplx_meth__6)(std::vector<cmplx> & smthg_out, color & colorstruct, int & number_out);
	opcd (COID_TABLE_TestClass_27_0::*cmplx_meth_in__7)(std::vector<cmplx> & smthg_in, color & colorstruct, int & number_in);
	opcd (COID_TABLE_TestClass_27_0::*array_of_int__8)(std::vector<int> int_array);
	opcd (COID_TABLE_TestClass_27_0::*get_string_vector__9)( std::vector<std::string> & string_vector_out );
	opcd (COID_TABLE_TestClass_27_0::*set_string_vector__10)( std::vector<std::string> & string_vector_in );
	opcd (COID_TABLE_TestClass_27_0::*set_vv_cmplx_and_trivType__11)( std::vector<std::vector<cmplx> > & vv_cmplx_in, std::vector<std::vector<trivTypes> > & vv_trivTypes_in );
	opcd (COID_TABLE_TestClass_27_0::*get_vv_cmplx_and_trivType__12)( std::vector<std::vector<cmplx> > & vv_cmplx_out, std::vector<std::vector<trivTypes> > & vv_trivTypes_out );
	opcd (COID_TABLE_TestClass_27_0::*set_personal_data__13)( person & person_in_out );
	opcd (COID_TABLE_TestClass_27_0::*set_address__14)( address_struct & address );
	opcd (COID_TABLE_TestClass_27_0::*calculate__15)( calculator & calcul_in_out );
};

}	// namespace coid



#define ___COID_CONNECTWITHIN_TRY		try {
#define ___COID_CONNECTWITHIN_CATCH	} catch( opcd ___coid_err ) {return ___coid_err;}\
										catch(...) { return ersFE_EXCEPTION "client method exception"; }
#define ___COID_CONNECT_TRY		try {
#define ___COID_CONNECT_CATCH		} catch( opcd ___coid_err ) {delete _coid_bstream; return ___coid_err;}\
									catch( ThreadException & ) { delete _coid_bstream; throw; }\
									catch(...) { delete _coid_bstream; return ersFE_EXCEPTION "client method exception"; }





const version COID_version_TestClass_27_0( "", 27, 0, 81 );

static COID_NICK g_coid_nick;

namespace coid {

static COID_TABLE_TestClass_27_0 * coid_interprocess_vtbl = NULL;
static COID_TABLE_TestClass_27_0 * coid_remote_vtbl = NULL;
static comm_mutex coid_table_mx( true, "COID_TABLE_TestClass_27_0" );

struct TABLE_REMOVER_TestClass_27_0 {
	~TABLE_REMOVER_TestClass_27_0() {delete coid_interprocess_vtbl; delete coid_remote_vtbl;}
};
static TABLE_REMOVER_TestClass_27_0	TestClass_27_0_table_trash;





enum {	/// command ids, format is: COID_classname_fncname_fncid
	COID_TestClass_get_length_0 = 0,
	COID_TestClass_get_vect_length_1 = 1,
	COID_TestClass_multiply_2 = 2,
	COID_TestClass_add_one_3 = 3,
	COID_TestClass_set_status_4 = 4,
	COID_TestClass_set_birth_date_5 = 5,
	COID_TestClass_cmplx_meth_6 = 6,
	COID_TestClass_cmplx_meth_in_7 = 7,
	COID_TestClass_array_of_int_8 = 8,
	COID_TestClass_get_string_vector_9 = 9,
	COID_TestClass_set_string_vector_10 = 10,
	COID_TestClass_set_vv_cmplx_and_trivType_11 = 11,
	COID_TestClass_get_vv_cmplx_and_trivType_12 = 12,
	COID_TestClass_set_personal_data_13 = 13,
	COID_TestClass_set_address_14 = 14,
	COID_TestClass_calculate_15 = 15
};




static uint COID_method_flags_TestClass[16] = {
	0x70000,
	0x70000,
	0x70000,
	0x70000,
	0x70000,
	0x70000,
	0x70000,
	0x70000,
	0x70000,
	0x70000,
	0x70000,
	0x70000,
	0x70000,
	0x70000,
	0x70000,
	0x70000
};




/***************************************************************************
TestClass_localclient
***************************************************************************/

class TestClass_localclient
{
public:
	COID_CLIENT cc;

	static void coid_init_table( uint coid_stream_flags, COID_TABLE_TestClass_27_0 *& table );
public:
   TestClass_localclient( netstream * b, binstream * b2 ) : cc(b, b2) {}
   void coid_throw();
   opcd disconnect() { return cc.disconnect(); }


	opcd get_length( int & length, const std::string & str );
	opcd get_vect_length( int & length, const std::vector<trivTypes> & vec );
	opcd multiply( double a, double b, double & result );
	opcd add_one( int & number );
	opcd set_status( int & old_status, int new_status );
	opcd set_birth_date(std::vector< birth_date > & birt_d);
	opcd cmplx_meth(std::vector<cmplx> & smthg_out, color & colorstruct, int & number_out);
	opcd cmplx_meth_in(std::vector<cmplx> & smthg_in, color & colorstruct, int & number_in);
	opcd array_of_int(std::vector<int> int_array);
	opcd get_string_vector( std::vector<std::string> & string_vector_out );
	opcd set_string_vector( std::vector<std::string> & string_vector_in );
	opcd set_vv_cmplx_and_trivType( std::vector<std::vector<cmplx> > & vv_cmplx_in, std::vector<std::vector<trivTypes> > & vv_trivTypes_in );
	opcd get_vv_cmplx_and_trivType( std::vector<std::vector<cmplx> > & vv_cmplx_out, std::vector<std::vector<trivTypes> > & vv_trivTypes_out );
	opcd set_personal_data( person & person_in_out );
	opcd set_address( address_struct & address );
	opcd calculate( calculator & calcul_in_out );
};



/// fake function:
void TestClass_localclient::coid_throw() {throw ersFE_EXCEPTION;}


typedef void (TestClass_localclient::*coid_fnc)();

#define COID_CLIENT_CREATE_HOOK(M,i,t,tc)\
	if( COID_method_flags_TestClass[i] & coid_stream_flags ) ((coid_fnc *) table)[t] = (coid_fnc) (tc) &TestClass_localclient::M;\
	else ((coid_fnc *) table)[t] = (coid_fnc) &TestClass_localclient::coid_throw;

#define COID_CLIENT_CREATE_DISCONNECT_HOOK(t)\
	((coid_fnc *) table)[t] = (coid_fnc) &TestClass_localclient::disconnect;





void inline TestClass_localclient::coid_init_table( uint coid_stream_flags, COID_TABLE_TestClass_27_0 *& table )
{
	table = new COID_TABLE_TestClass_27_0;

	uint coid_table_index = 0;
	COID_CLIENT_CREATE_DISCONNECT_HOOK( coid_table_index++ )
	COID_CLIENT_CREATE_HOOK( get_length, 0, coid_table_index++, opcd (TestClass_localclient::*)( int & , const std::string &  ) )
	COID_CLIENT_CREATE_HOOK( get_vect_length, 1, coid_table_index++, opcd (TestClass_localclient::*)( int & , const std::vector<trivTypes> &  ) )
	COID_CLIENT_CREATE_HOOK( multiply, 2, coid_table_index++, opcd (TestClass_localclient::*)( double , double , double &  ) )
	COID_CLIENT_CREATE_HOOK( add_one, 3, coid_table_index++, opcd (TestClass_localclient::*)( int &  ) )
	COID_CLIENT_CREATE_HOOK( set_status, 4, coid_table_index++, opcd (TestClass_localclient::*)( int & , int  ) )
	COID_CLIENT_CREATE_HOOK( set_birth_date, 5, coid_table_index++, opcd (TestClass_localclient::*)(std::vector< birth_date > & ) )
	COID_CLIENT_CREATE_HOOK( cmplx_meth, 6, coid_table_index++, opcd (TestClass_localclient::*)(std::vector<cmplx> & , color & , int & ) )
	COID_CLIENT_CREATE_HOOK( cmplx_meth_in, 7, coid_table_index++, opcd (TestClass_localclient::*)(std::vector<cmplx> & , color & , int & ) )
	COID_CLIENT_CREATE_HOOK( array_of_int, 8, coid_table_index++, opcd (TestClass_localclient::*)(std::vector<int> ) )
	COID_CLIENT_CREATE_HOOK( get_string_vector, 9, coid_table_index++, opcd (TestClass_localclient::*)( std::vector<std::string> &  ) )
	COID_CLIENT_CREATE_HOOK( set_string_vector, 10, coid_table_index++, opcd (TestClass_localclient::*)( std::vector<std::string> &  ) )
	COID_CLIENT_CREATE_HOOK( set_vv_cmplx_and_trivType, 11, coid_table_index++, opcd (TestClass_localclient::*)( std::vector<std::vector<cmplx> > & , std::vector<std::vector<trivTypes> > &  ) )
	COID_CLIENT_CREATE_HOOK( get_vv_cmplx_and_trivType, 12, coid_table_index++, opcd (TestClass_localclient::*)( std::vector<std::vector<cmplx> > & , std::vector<std::vector<trivTypes> > &  ) )
	COID_CLIENT_CREATE_HOOK( set_personal_data, 13, coid_table_index++, opcd (TestClass_localclient::*)( person &  ) )
	COID_CLIENT_CREATE_HOOK( set_address, 14, coid_table_index++, opcd (TestClass_localclient::*)( address_struct &  ) )
	COID_CLIENT_CREATE_HOOK( calculate, 15, coid_table_index++, opcd (TestClass_localclient::*)( calculator &  ) )
}






opcd TestClass_localclient::get_length( int & length, const std::string & str )
{
	*cc._coid_bstream << (uint) COID_TestClass_get_length_0;
	*cc._coid_bstream << cc._coid_inst_id;
	*cc._coid_bstream << str;

	cc._coid_bstream->flush();
	cc._coid_err_code = cc._coid_bstream->get_error();
	if( cc._coid_err_code ) {
		cc._coid_bstream->acknowledge();
		return cc._coid_err_code;
	}
	*cc._coid_bstream >> length;

	cc._coid_bstream->acknowledge();

	return cc._coid_err_code;
}



opcd TestClass_localclient::get_vect_length( int & length, const std::vector<trivTypes> & vec )
{
	*cc._coid_bstream << (uint) COID_TestClass_get_vect_length_1;
	*cc._coid_bstream << cc._coid_inst_id;
	*cc._coid_bstream << vec;

	cc._coid_bstream->flush();
	cc._coid_err_code = cc._coid_bstream->get_error();
	if( cc._coid_err_code ) {
		cc._coid_bstream->acknowledge();
		return cc._coid_err_code;
	}
	*cc._coid_bstream >> length;

	cc._coid_bstream->acknowledge();

	return cc._coid_err_code;
}



opcd TestClass_localclient::multiply( double a, double b, double & result )
{
	*cc._coid_bstream << (uint) COID_TestClass_multiply_2;
	*cc._coid_bstream << cc._coid_inst_id;
	*cc._coid_bstream << a;
	*cc._coid_bstream << b;

	cc._coid_bstream->flush();
	cc._coid_err_code = cc._coid_bstream->get_error();
	if( cc._coid_err_code ) {
		cc._coid_bstream->acknowledge();
		return cc._coid_err_code;
	}
	*cc._coid_bstream >> result;

	cc._coid_bstream->acknowledge();

	return cc._coid_err_code;
}



opcd TestClass_localclient::add_one( int & number )
{
	*cc._coid_bstream << (uint) COID_TestClass_add_one_3;
	*cc._coid_bstream << cc._coid_inst_id;
	*cc._coid_bstream << number;

	cc._coid_bstream->flush();
	cc._coid_err_code = cc._coid_bstream->get_error();
	if( cc._coid_err_code ) {
		cc._coid_bstream->acknowledge();
		return cc._coid_err_code;
	}
	*cc._coid_bstream >> number;

	cc._coid_bstream->acknowledge();

	return cc._coid_err_code;
}



opcd TestClass_localclient::set_status( int & old_status, int new_status )
{
	*cc._coid_bstream << (uint) COID_TestClass_set_status_4;
	*cc._coid_bstream << cc._coid_inst_id;
	*cc._coid_bstream << new_status;

	cc._coid_bstream->flush();
	cc._coid_err_code = cc._coid_bstream->get_error();
	if( cc._coid_err_code ) {
		cc._coid_bstream->acknowledge();
		return cc._coid_err_code;
	}
	*cc._coid_bstream >> old_status;

	cc._coid_bstream->acknowledge();

	return cc._coid_err_code;
}



opcd TestClass_localclient::set_birth_date(std::vector< birth_date > & birt_d)
{
	*cc._coid_bstream << (uint) COID_TestClass_set_birth_date_5;
	*cc._coid_bstream << cc._coid_inst_id;
	*cc._coid_bstream << birt_d;

	cc._coid_bstream->flush();
	cc._coid_err_code = cc._coid_bstream->get_error();
	if( cc._coid_err_code ) {
		cc._coid_bstream->acknowledge();
		return cc._coid_err_code;
	}

	cc._coid_bstream->acknowledge();

	return cc._coid_err_code;
}



opcd TestClass_localclient::cmplx_meth(std::vector<cmplx> & smthg_out, color & colorstruct, int & number_out)
{
	*cc._coid_bstream << (uint) COID_TestClass_cmplx_meth_6;
	*cc._coid_bstream << cc._coid_inst_id;

	cc._coid_bstream->flush();
	cc._coid_err_code = cc._coid_bstream->get_error();
	if( cc._coid_err_code ) {
		cc._coid_bstream->acknowledge();
		return cc._coid_err_code;
	}
	*cc._coid_bstream >> smthg_out;
	*cc._coid_bstream >> colorstruct;
	*cc._coid_bstream >> number_out;

	cc._coid_bstream->acknowledge();

	return cc._coid_err_code;
}



opcd TestClass_localclient::cmplx_meth_in(std::vector<cmplx> & smthg_in, color & colorstruct, int & number_in)
{
	*cc._coid_bstream << (uint) COID_TestClass_cmplx_meth_in_7;
	*cc._coid_bstream << cc._coid_inst_id;
	*cc._coid_bstream << smthg_in;
	*cc._coid_bstream << colorstruct;
	*cc._coid_bstream << number_in;

	cc._coid_bstream->flush();
	cc._coid_err_code = cc._coid_bstream->get_error();
	if( cc._coid_err_code ) {
		cc._coid_bstream->acknowledge();
		return cc._coid_err_code;
	}

	cc._coid_bstream->acknowledge();

	return cc._coid_err_code;
}



opcd TestClass_localclient::array_of_int(std::vector<int> int_array)
{
	*cc._coid_bstream << (uint) COID_TestClass_array_of_int_8;
	*cc._coid_bstream << cc._coid_inst_id;
	*cc._coid_bstream << int_array;

	cc._coid_bstream->flush();
	cc._coid_err_code = cc._coid_bstream->get_error();
	if( cc._coid_err_code ) {
		cc._coid_bstream->acknowledge();
		return cc._coid_err_code;
	}

	cc._coid_bstream->acknowledge();

	return cc._coid_err_code;
}



opcd TestClass_localclient::get_string_vector( std::vector<std::string> & string_vector_out )
{
	*cc._coid_bstream << (uint) COID_TestClass_get_string_vector_9;
	*cc._coid_bstream << cc._coid_inst_id;

	cc._coid_bstream->flush();
	cc._coid_err_code = cc._coid_bstream->get_error();
	if( cc._coid_err_code ) {
		cc._coid_bstream->acknowledge();
		return cc._coid_err_code;
	}
	*cc._coid_bstream >> string_vector_out;

	cc._coid_bstream->acknowledge();

	return cc._coid_err_code;
}



opcd TestClass_localclient::set_string_vector( std::vector<std::string> & string_vector_in )
{
	*cc._coid_bstream << (uint) COID_TestClass_set_string_vector_10;
	*cc._coid_bstream << cc._coid_inst_id;
	*cc._coid_bstream << string_vector_in;

	cc._coid_bstream->flush();
	cc._coid_err_code = cc._coid_bstream->get_error();
	if( cc._coid_err_code ) {
		cc._coid_bstream->acknowledge();
		return cc._coid_err_code;
	}

	cc._coid_bstream->acknowledge();

	return cc._coid_err_code;
}



opcd TestClass_localclient::set_vv_cmplx_and_trivType( std::vector<std::vector<cmplx> > & vv_cmplx_in, std::vector<std::vector<trivTypes> > & vv_trivTypes_in )
{
	*cc._coid_bstream << (uint) COID_TestClass_set_vv_cmplx_and_trivType_11;
	*cc._coid_bstream << cc._coid_inst_id;
	*cc._coid_bstream << vv_cmplx_in;
	*cc._coid_bstream << vv_trivTypes_in;

	cc._coid_bstream->flush();
	cc._coid_err_code = cc._coid_bstream->get_error();
	if( cc._coid_err_code ) {
		cc._coid_bstream->acknowledge();
		return cc._coid_err_code;
	}

	cc._coid_bstream->acknowledge();

	return cc._coid_err_code;
}



opcd TestClass_localclient::get_vv_cmplx_and_trivType( std::vector<std::vector<cmplx> > & vv_cmplx_out, std::vector<std::vector<trivTypes> > & vv_trivTypes_out )
{
	*cc._coid_bstream << (uint) COID_TestClass_get_vv_cmplx_and_trivType_12;
	*cc._coid_bstream << cc._coid_inst_id;

	cc._coid_bstream->flush();
	cc._coid_err_code = cc._coid_bstream->get_error();
	if( cc._coid_err_code ) {
		cc._coid_bstream->acknowledge();
		return cc._coid_err_code;
	}
	*cc._coid_bstream >> vv_cmplx_out;
	*cc._coid_bstream >> vv_trivTypes_out;

	cc._coid_bstream->acknowledge();

	return cc._coid_err_code;
}



opcd TestClass_localclient::set_personal_data( person & person_in_out )
{
	*cc._coid_bstream << (uint) COID_TestClass_set_personal_data_13;
	*cc._coid_bstream << cc._coid_inst_id;
	*cc._coid_bstream << person_in_out;

	cc._coid_bstream->flush();
	cc._coid_err_code = cc._coid_bstream->get_error();
	if( cc._coid_err_code ) {
		cc._coid_bstream->acknowledge();
		return cc._coid_err_code;
	}

	cc._coid_bstream->acknowledge();

	return cc._coid_err_code;
}



opcd TestClass_localclient::set_address( address_struct & address )
{
	*cc._coid_bstream << (uint) COID_TestClass_set_address_14;
	*cc._coid_bstream << cc._coid_inst_id;
	*cc._coid_bstream << address;

	cc._coid_bstream->flush();
	cc._coid_err_code = cc._coid_bstream->get_error();
	if( cc._coid_err_code ) {
		cc._coid_bstream->acknowledge();
		return cc._coid_err_code;
	}

	cc._coid_bstream->acknowledge();

	return cc._coid_err_code;
}



opcd TestClass_localclient::calculate( calculator & calcul_in_out )
{
	*cc._coid_bstream << (uint) COID_TestClass_calculate_15;
	*cc._coid_bstream << cc._coid_inst_id;
	*cc._coid_bstream << calcul_in_out;

	cc._coid_bstream->flush();
	cc._coid_err_code = cc._coid_bstream->get_error();
	if( cc._coid_err_code ) {
		cc._coid_bstream->acknowledge();
		return cc._coid_err_code;
	}
	*cc._coid_bstream >> calcul_in_out;

	cc._coid_bstream->acknowledge();

	return cc._coid_err_code;
}




/***************************************************************************
TestClass_client
***************************************************************************/

TestClass_client::TestClass_client() : _me(NULL), _vtbl(NULL), _conn_data(0), _timeout(0)
{
	netSubsystem::instance();
}
TestClass_client::~TestClass_client()
{
	disconnect();
}
TestClass_client::TestClass_client( const TestClass_client & c ) {throw ersFE_EXCEPTION;}
TestClass_client & TestClass_client::operator = ( const TestClass_client & c ) {throw ersFE_EXCEPTION; return *this;}

void TestClass_client::destroy_me()
{
	if( get_connection_type() != ConnectFlags::fACCESS_MODE_DIRECT )
		delete (TestClass_localclient *) _me;
	_me = NULL;
}

opcd TestClass_client::disconnect()
{
	if( !is_connected() )
		return 0;
	DASSERT( _mx_reg.is_valid() );
	comm_mutex & lowlevelmx = _mx_reg._mxc->_mx;
	bool last = false;
	opcd coid_err;
	try {
		extendedGUARD_lock( _mx_reg );
		DASSERT( _me );
		coid_err = ((get_connection_type() == ConnectFlags::fACCESS_MODE_DIRECT ? (COID_TABLE_TestClass_27_0 *) this : _me)->*(_vtbl->disconnect)) ();
		destroy_me();
		if( _mx_reg.counter_fast() == 1 ) {
			_mx_reg.disable_fast();
			lowlevelmx.unlock();
			__coid__mxg.eject();
			last = true;
		}
	}
	catch( opcd e ) {
		destroy_me(); coid_err = e;
	}

	if( last ) {
#ifdef _DEBUG
		const int max = 0xFFFF;
#else
		const int max = 10;
#endif
		int i=0;
		for( ; i<max; i++ ) {
			if( lowlevelmx.try_lock() ) {lowlevelmx.unlock(); break;}
			sysMilliSecondSleep( 10 );
		}
		if( i == max ) throw ersFE_EXCEPTION;
	}

	_mx_reg.destroy_all();
	_vtbl = NULL;
	set_connection_type( 0 );
	return coid_err;
}

opcd TestClass_client::get_last_error() const
{
	if( !is_connected() ) return 0;
	if( get_connection_type() == ConnectFlags::fACCESS_MODE_REMOTE ) return ((COID_CLIENT *) _me)->get_last_error();
	else if( get_connection_type() == ConnectFlags::fACCESS_MODE_INTERPROCESS ) return ((COID_CLIENT *) _me)->get_last_error();
	return 0;
}

void TestClass_client::set_last_error( opcd e )
{
	if( !is_connected() ) return;
	if( get_connection_type() == ConnectFlags::fACCESS_MODE_REMOTE ) ((COID_CLIENT *) _me)->set_last_error( e );
	else if( get_connection_type() == ConnectFlags::fACCESS_MODE_INTERPROCESS ) ((COID_CLIENT *) _me)->set_last_error( e );
}

inline bool TestClass_client::setup_members( uint coid_stream_flags, netstream * bstream, binstream * bstream2, comm_mutex_reg * mx_reg )
{
	disconnect();
	set_connection_type( coid_stream_flags );

	if( coid_stream_flags == ConnectFlags::fACCESS_MODE_DIRECT ) {	/// direct
		if( !bstream2 ) bstream2 = bstream;
		bstream2->read_ptr(_vtbl);
		bstream2->read_ptr(_me);
		comm_mutex_reg::refmutex* _rmx;
		bstream2->read_ptr(_rmx);
		_mx_reg.init( *_rmx );
		bstream2->acknowledge();
		delete bstream;
	}
	else if( coid_stream_flags == ConnectFlags::fACCESS_MODE_INTERPROCESS ) {	/// interprocess
		if( !bstream2 ) bstream2 = bstream;
		if( coid_interprocess_vtbl ) _vtbl = coid_interprocess_vtbl;
		else {
			MXGUARD( coid_table_mx );
			if( !coid_interprocess_vtbl )
				TestClass_localclient::coid_init_table( coid_stream_flags, coid_interprocess_vtbl );
			_vtbl = coid_interprocess_vtbl;
		}
		_me = (COID_TABLE_TestClass_27_0 *) new TestClass_localclient( bstream, bstream2 );
		bstream2->acknowledge();
		_mx_reg.init( mx_reg, true, "TestClass_client" );
		_mx_reg._p1 = bstream;
	}
	else if( coid_stream_flags == ConnectFlags::fACCESS_MODE_REMOTE ) {	/// remote
		if( !bstream2 ) bstream2 = bstream;
		if( coid_remote_vtbl ) _vtbl = coid_remote_vtbl;
		else {
			MXGUARD( coid_table_mx );
			if( !coid_remote_vtbl )
				TestClass_localclient::coid_init_table( coid_stream_flags, coid_remote_vtbl );
			_vtbl = coid_remote_vtbl;
		}
		_me = (COID_TABLE_TestClass_27_0 *) new TestClass_localclient( bstream, bstream2 );
		bstream2->acknowledge();
		_mx_reg.init( mx_reg, true, "TestClass_client" );
		_mx_reg._p1 = bstream;
	}
	else throw ersFE_EXCEPTION;

	return true;
}

void TestClass_client::setup_stream( binstream& b, uint coid_flags, uint coid_obj_id ) const
{
	if( coid_flags & ConnectFlags::fWITHIN_CHANNEL ) {
		coid_flags &= ~ConnectFlags::fWITHIN_CHANNEL;
		b << StdProtocolMethod::CONNECT;
	}
	uchar conchar = StdProtocolMethod::CONNECT_CHAR;
	b << conchar << version(COID_VERSION);
	b << g_coid_nick << coid_flags << COID_version_TestClass_27_0 << "TestClass";
	b << (uint) 16;
   b.write_ptr(COID_method_flags_TestClass);
   b << coid_obj_id << sysGetPid();
   b.write_ptr(this);
}

opcd TestClass_client::ping_server( const char * coid_address, uint coid_obj_id, uint coid_flags ) const
{
	coid_flags |= ConnectFlags::fPING_SERVER;
	charstr tmp;
	netstream * _coid_bstream = COID_CLIENT::create_stream( "TestClass", coid_address, tmp, (coid_flags & ConnectFlags::fTUNNEL) != 0 );
	if( !_coid_bstream ) return ersFE_UNREACHABLE;
	if( _timeout ) _coid_bstream->set_timeout( _timeout );
	coid_flags &= ~ConnectFlags::fTUNNEL;
	setup_stream( *_coid_bstream, coid_flags, coid_obj_id );
	___COID_CONNECT_TRY
	_coid_bstream->flush();
	opcd _coid_err_code = _coid_bstream->get_error();
	_coid_bstream->acknowledge();
	delete _coid_bstream;
	return _coid_err_code;

	___COID_CONNECT_CATCH
}

opcd TestClass_client::set_timeout( uint milliseconds )
{
	if( milliseconds == _timeout ) return 0;
	_timeout = milliseconds;
	if( !is_connected() ) return 0;
	if( get_connection_type() == ConnectFlags::fACCESS_MODE_DIRECT ) return 0;
	netstream * n = ((COID_CLIENT *) _me)->get_stream();
	if( !n ) return ersFAILED;
	return n->set_timeout( _timeout );
}








opcd TestClass_client::connect( int status_init, const char * coid_address, uint coid_flags )
{
	_addr.reset();
	extendedGUARD_reg __coid__mxg( _mx_reg, false );
	if( _mx_reg.is_valid() ) {
		if( get_connection_type() == ConnectFlags::fACCESS_MODE_DIRECT ) {	/// direct
			return ersFE_ALREADY_CONNECTED;
		}
		else if( get_connection_type() == ConnectFlags::fACCESS_MODE_INTERPROCESS ) {	/// interprocess
			__coid__mxg.lock();
			if( ((COID_CLIENT *)_me)->is_stream_open() )
				return ersFE_ALREADY_CONNECTED;
		}
		else if( get_connection_type() == ConnectFlags::fACCESS_MODE_REMOTE ) {	/// remote
			__coid__mxg.lock();
			if( ((COID_CLIENT *)_me)->is_stream_open() )
				return ersFE_ALREADY_CONNECTED;
		}
	}

	netstream * _coid_bstream = COID_CLIENT::create_stream( "TestClass", coid_address, _addr, (coid_flags & ConnectFlags::fTUNNEL) != 0 );
	if( !_coid_bstream ) return ersFE_UNREACHABLE;
	if( _timeout ) _coid_bstream->set_timeout( _timeout );
	coid_flags &= ~ConnectFlags::fTUNNEL;
	setup_stream( *_coid_bstream, coid_flags, UMAX );
	___COID_CONNECT_TRY
	*_coid_bstream << status_init;

	_coid_bstream->flush();
	opcd _coid_err_code = _coid_bstream->get_error();
	if( _coid_err_code ) {
		_coid_bstream->acknowledge(true);
		delete _coid_bstream;
		return _coid_err_code;
	}

	uint coid_stream_flags;
	*_coid_bstream >> coid_stream_flags;
	RASSERT( coid_stream_flags & ConnectFlags::xACCESS_MODE );
	setup_members( coid_stream_flags, _coid_bstream, _coid_bstream );

	return _coid_err_code;

	___COID_CONNECT_CATCH
}








opcd TestClass_client::connect_within( comm_mutex_reg & coid_channel, int status_init )
{
	if( !coid_channel.is_set() ) return ersFE_CHANNEL;
	_addr.reset();
	extendedGUARD_reg __coid__mxg( coid_channel, true );

	netstream * _coid_bstream = (netstream *) ((comm_mutex_custom_reg<netstream, void*> &) coid_channel)._p1;
	if( !_coid_bstream ) return ersFE_UNREACHABLE;
	/// we must avoid direct access mode
	setup_stream( *_coid_bstream, ConnectFlags::fACCESS_MODE_REMOTE | ConnectFlags::fACCESS_MODE_INTERPROCESS | ConnectFlags::fWITHIN_CHANNEL, UMAX );
	___COID_CONNECTWITHIN_TRY
	*_coid_bstream << status_init;

	_coid_bstream->flush();
	opcd _coid_err_code = _coid_bstream->get_error();
	if( _coid_err_code ) {
		_coid_bstream->acknowledge();
		return _coid_err_code;
	}

	uint coid_stream_flags;
	*_coid_bstream >> coid_stream_flags;
	RASSERT( coid_stream_flags & ConnectFlags::xACCESS_MODE );
	setup_members( coid_stream_flags, _coid_bstream, _coid_bstream, &coid_channel );

	return _coid_err_code;

	___COID_CONNECTWITHIN_CATCH
}






opcd TestClass_client::connect_shared( uint coid_obj_id,  const char * coid_address, uint coid_flags  )
{
	_addr.reset();
	extendedGUARD_reg __coid__mxg( _mx_reg, false );
	if( _mx_reg.is_valid() ) {
		if( get_connection_type() == ConnectFlags::fACCESS_MODE_DIRECT ) {	/// direct
			return ersFE_ALREADY_CONNECTED;
		}
		else if( get_connection_type() == ConnectFlags::fACCESS_MODE_INTERPROCESS ) {	/// interprocess
			__coid__mxg.lock();
			if( ((COID_CLIENT *)_me)->is_stream_open() )
				return ersFE_ALREADY_CONNECTED;
		}
		else if( get_connection_type() == ConnectFlags::fACCESS_MODE_REMOTE ) {	/// remote
			__coid__mxg.lock();
			if( ((COID_CLIENT *)_me)->is_stream_open() )
				return ersFE_ALREADY_CONNECTED;
		}
	}

	netstream * _coid_bstream = COID_CLIENT::create_stream( "TestClass", coid_address, _addr, (coid_flags & ConnectFlags::fTUNNEL) != 0 );
	if( !_coid_bstream ) return ersFE_UNREACHABLE;
	if( _timeout ) _coid_bstream->set_timeout( _timeout );
	coid_flags &= ~ConnectFlags::fTUNNEL;
	setup_stream( *_coid_bstream, coid_flags, coid_obj_id );
	___COID_CONNECT_TRY

	_coid_bstream->flush();
	opcd _coid_err_code = _coid_bstream->get_error();
	if( _coid_err_code ) {
		_coid_bstream->acknowledge(true);
		delete _coid_bstream;
		return _coid_err_code;
	}

	uint coid_stream_flags;
	*_coid_bstream >> coid_stream_flags;
	RASSERT( coid_stream_flags & ConnectFlags::xACCESS_MODE );
	setup_members( coid_stream_flags, _coid_bstream, _coid_bstream );

	return _coid_err_code;

	___COID_CONNECT_CATCH
}









opcd TestClass_client::get_length( int & length, const std::string & str )
{
	opcd _coid_err_code;
#ifndef TestClass_NOTHROW
	try {
#endif
		extendedGUARD_lock( _mx_reg );
		if( !_me ) return ersFE_DISCONNECTED;
		_coid_err_code = (_me->*(_vtbl->get_length__0)) (length, str);
#ifndef TestClass_NOTHROW
	}
	catch( opcd e ) {_coid_err_code = e;}
#endif
	return _coid_err_code;
}

opcd TestClass_client::get_vect_length( int & length, const std::vector<trivTypes> & vec )
{
	opcd _coid_err_code;
#ifndef TestClass_NOTHROW
	try {
#endif
		extendedGUARD_lock( _mx_reg );
		if( !_me ) return ersFE_DISCONNECTED;
		_coid_err_code = (_me->*(_vtbl->get_vect_length__1)) (length, vec);
#ifndef TestClass_NOTHROW
	}
	catch( opcd e ) {_coid_err_code = e;}
#endif
	return _coid_err_code;
}

opcd TestClass_client::multiply( double a, double b, double & result )
{
	opcd _coid_err_code;
#ifndef TestClass_NOTHROW
	try {
#endif
		extendedGUARD_lock( _mx_reg );
		if( !_me ) return ersFE_DISCONNECTED;
		_coid_err_code = (_me->*(_vtbl->multiply__2)) (a, b, result);
#ifndef TestClass_NOTHROW
	}
	catch( opcd e ) {_coid_err_code = e;}
#endif
	return _coid_err_code;
}

opcd TestClass_client::add_one( int & number )
{
	opcd _coid_err_code;
#ifndef TestClass_NOTHROW
	try {
#endif
		extendedGUARD_lock( _mx_reg );
		if( !_me ) return ersFE_DISCONNECTED;
		_coid_err_code = (_me->*(_vtbl->add_one__3)) (number);
#ifndef TestClass_NOTHROW
	}
	catch( opcd e ) {_coid_err_code = e;}
#endif
	return _coid_err_code;
}

opcd TestClass_client::set_status( int & old_status, int new_status )
{
	opcd _coid_err_code;
#ifndef TestClass_NOTHROW
	try {
#endif
		extendedGUARD_lock( _mx_reg );
		if( !_me ) return ersFE_DISCONNECTED;
		_coid_err_code = (_me->*(_vtbl->set_status__4)) (old_status, new_status);
#ifndef TestClass_NOTHROW
	}
	catch( opcd e ) {_coid_err_code = e;}
#endif
	return _coid_err_code;
}

opcd TestClass_client::set_birth_date(std::vector< birth_date > & birt_d)
{
	opcd _coid_err_code;
#ifndef TestClass_NOTHROW
	try {
#endif
		extendedGUARD_lock( _mx_reg );
		if( !_me ) return ersFE_DISCONNECTED;
		_coid_err_code = (_me->*(_vtbl->set_birth_date__5)) (birt_d);
#ifndef TestClass_NOTHROW
	}
	catch( opcd e ) {_coid_err_code = e;}
#endif
	return _coid_err_code;
}

opcd TestClass_client::cmplx_meth(std::vector<cmplx> & smthg_out, color & colorstruct, int & number_out)
{
	opcd _coid_err_code;
#ifndef TestClass_NOTHROW
	try {
#endif
		extendedGUARD_lock( _mx_reg );
		if( !_me ) return ersFE_DISCONNECTED;
		_coid_err_code = (_me->*(_vtbl->cmplx_meth__6)) (smthg_out, colorstruct, number_out);
#ifndef TestClass_NOTHROW
	}
	catch( opcd e ) {_coid_err_code = e;}
#endif
	return _coid_err_code;
}

opcd TestClass_client::cmplx_meth_in(std::vector<cmplx> & smthg_in, color & colorstruct, int & number_in)
{
	opcd _coid_err_code;
#ifndef TestClass_NOTHROW
	try {
#endif
		extendedGUARD_lock( _mx_reg );
		if( !_me ) return ersFE_DISCONNECTED;
		_coid_err_code = (_me->*(_vtbl->cmplx_meth_in__7)) (smthg_in, colorstruct, number_in);
#ifndef TestClass_NOTHROW
	}
	catch( opcd e ) {_coid_err_code = e;}
#endif
	return _coid_err_code;
}

opcd TestClass_client::array_of_int(std::vector<int> int_array)
{
	opcd _coid_err_code;
#ifndef TestClass_NOTHROW
	try {
#endif
		extendedGUARD_lock( _mx_reg );
		if( !_me ) return ersFE_DISCONNECTED;
		_coid_err_code = (_me->*(_vtbl->array_of_int__8)) (int_array);
#ifndef TestClass_NOTHROW
	}
	catch( opcd e ) {_coid_err_code = e;}
#endif
	return _coid_err_code;
}

opcd TestClass_client::get_string_vector( std::vector<std::string> & string_vector_out )
{
	opcd _coid_err_code;
#ifndef TestClass_NOTHROW
	try {
#endif
		extendedGUARD_lock( _mx_reg );
		if( !_me ) return ersFE_DISCONNECTED;
		_coid_err_code = (_me->*(_vtbl->get_string_vector__9)) (string_vector_out);
#ifndef TestClass_NOTHROW
	}
	catch( opcd e ) {_coid_err_code = e;}
#endif
	return _coid_err_code;
}

opcd TestClass_client::set_string_vector( std::vector<std::string> & string_vector_in )
{
	opcd _coid_err_code;
#ifndef TestClass_NOTHROW
	try {
#endif
		extendedGUARD_lock( _mx_reg );
		if( !_me ) return ersFE_DISCONNECTED;
		_coid_err_code = (_me->*(_vtbl->set_string_vector__10)) (string_vector_in);
#ifndef TestClass_NOTHROW
	}
	catch( opcd e ) {_coid_err_code = e;}
#endif
	return _coid_err_code;
}

opcd TestClass_client::set_vv_cmplx_and_trivType( std::vector<std::vector<cmplx> > & vv_cmplx_in, std::vector<std::vector<trivTypes> > & vv_trivTypes_in )
{
	opcd _coid_err_code;
#ifndef TestClass_NOTHROW
	try {
#endif
		extendedGUARD_lock( _mx_reg );
		if( !_me ) return ersFE_DISCONNECTED;
		_coid_err_code = (_me->*(_vtbl->set_vv_cmplx_and_trivType__11)) (vv_cmplx_in, vv_trivTypes_in);
#ifndef TestClass_NOTHROW
	}
	catch( opcd e ) {_coid_err_code = e;}
#endif
	return _coid_err_code;
}

opcd TestClass_client::get_vv_cmplx_and_trivType( std::vector<std::vector<cmplx> > & vv_cmplx_out, std::vector<std::vector<trivTypes> > & vv_trivTypes_out )
{
	opcd _coid_err_code;
#ifndef TestClass_NOTHROW
	try {
#endif
		extendedGUARD_lock( _mx_reg );
		if( !_me ) return ersFE_DISCONNECTED;
		_coid_err_code = (_me->*(_vtbl->get_vv_cmplx_and_trivType__12)) (vv_cmplx_out, vv_trivTypes_out);
#ifndef TestClass_NOTHROW
	}
	catch( opcd e ) {_coid_err_code = e;}
#endif
	return _coid_err_code;
}

opcd TestClass_client::set_personal_data( person & person_in_out )
{
	opcd _coid_err_code;
#ifndef TestClass_NOTHROW
	try {
#endif
		extendedGUARD_lock( _mx_reg );
		if( !_me ) return ersFE_DISCONNECTED;
		_coid_err_code = (_me->*(_vtbl->set_personal_data__13)) (person_in_out);
#ifndef TestClass_NOTHROW
	}
	catch( opcd e ) {_coid_err_code = e;}
#endif
	return _coid_err_code;
}

opcd TestClass_client::set_address( address_struct & address )
{
	opcd _coid_err_code;
#ifndef TestClass_NOTHROW
	try {
#endif
		extendedGUARD_lock( _mx_reg );
		if( !_me ) return ersFE_DISCONNECTED;
		_coid_err_code = (_me->*(_vtbl->set_address__14)) (address);
#ifndef TestClass_NOTHROW
	}
	catch( opcd e ) {_coid_err_code = e;}
#endif
	return _coid_err_code;
}

opcd TestClass_client::calculate( calculator & calcul_in_out )
{
	opcd _coid_err_code;
#ifndef TestClass_NOTHROW
	try {
#endif
		extendedGUARD_lock( _mx_reg );
		if( !_me ) return ersFE_DISCONNECTED;
		_coid_err_code = (_me->*(_vtbl->calculate__15)) (calcul_in_out);
#ifndef TestClass_NOTHROW
	}
	catch( opcd e ) {_coid_err_code = e;}
#endif
	return _coid_err_code;
}



}	/// namespace coid
